package com.df.controller;

import com.df.bean.Product;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @program: codes
 * @description:
 * @author: df
 * @create: 2023-07-10 13:39:02
 **/
@RestController
public class ProductController {

    public static final Logger logger = LoggerFactory.getLogger(ProductController.class);

    @Value("${server.port}")
    private int port;

    @GetMapping("/product")
    public String product(){

        return "product port:"+ port;
    }

    @GetMapping("/test")
    public String test(int id, String name){
        logger.info("id: {},name: {}",id,name);
        return "product port:"+ port;
    }

    @GetMapping("/test1/{id}/{name}")
    public String test1(@PathVariable int id, @PathVariable String name){
        logger.info("id: {},name: {}",id,name);
        return "product port:"+ port;
    }

    @PostMapping("/product1")
    public String product(@RequestBody Product product){
        logger.info("product: {}",product);
        return "product port:"+ port;
    }

    @PostMapping("/array")
    public String array(@RequestParam Integer[] ids){
        Arrays.asList(ids).forEach(id->{
            logger.info(String.valueOf(id));
        });

        return "product port:"+ port;
    }

    @GetMapping("/get")
    public Product get(@RequestParam int id){

        return new Product(1,"df");
    }
}
